1 <?php
2     
3     session_start();
4     require
"includes/functions.php";
5     require
"includes/db.php";
6     
if(!isset($_SESSION['user'])) {
7         header(
"location: logout.php");
8     }
9     
10     $result =
"";
11     $info =
"";
12     $items =
"";
13     
14     
if($_SERVER['REQUEST_METHOD'] == 'POST') {
15         
16         
if(isset($_POST['order_id'])) {
17             
18             $order_id = htmlentities($_POST[
'order_id'], ENT_QUOTES, 'UTF-8');
19             
20             
if($order_id != "") {
21                 
22                 $arr_id = explode(
"_", $order_id);
23                 
24                 $id = $arr_id[
0];
25                 
26                 $order = $db->query(
"SELECT * FROM basket WHERE id='".$id."' LIMIT 1");
27                 
28                 
if($order->num_rows) {
29                     
30                     $row = $order->fetch_assoc();
31                     
32                     $info .=
"<table class='table table-hover'>
33                         <thead>
34                             <th>Order_id</th>
35                             <th>Tên</th>
36                             <th>Địa chỉ</th>
37                             <th>Email</th>
38                             <th>Di động</th>
39                         </thead>
40                         <tbody>"
;
41                         
42                     $items .=
"<table class='table table-hover'>
43                         <tbody>
44                         <tr>
45                             <th>Tên</th>
46                             <th>Số lượng</th>
47                             <td></td>
48                         </tr>"
;
49                         
50                     $info .=
"<tr>
51                                 <td>ORD_$id</td>
52                                 <td>"
.$row['customer_name']."</td>
53                                 <td>"
.$row['address']."</td>
54                                 <td>"
.$row['email']."</td>
55                                 <td>"
.$row['contact_number']."</td>
56                             </tr>"
;
57                             
58                     $get_data = $db->query(
"SELECT * FROM items WHERE order_id='".$id."'");
59                     
60                     
61                     
while($data = $get_data->fetch_assoc()) {
62                         
63                         $items .=
"<tr>
64                                         <td>"
.$data['food']."</td>
65                                         <td>"
.$data['qty']."</td>
66                                         <td></td>
67                                     </tr>"
;
68                         
69                     }
70                     
71                     $items .=
"<tr>
72                                     <th>Tổng tiền</th>
73                                     <th>"
.$row['total']."</th>
74                                     <th></th>
75                                 </tr>
76                                 "
;
77                     
78                     
if($row['status'] == "pending") {
79                         
80                         $items .=
"<tr>
81                                     <th>Trạng thái</th>
82                                     <td>
83                                         <
select onChange=\"change_stat('".$id."')\" name='status' id='".$id."' class='form-control'>
84                                             <option
value='pending_$id' selected>Chờ xử lý</option>
85                                             <option
value='confirmed_$id'>Đã hoàn thành</option>
86                                         </
select>
87                                     </td>
88                                     <th></th>
89                                 </tr>"
;
90                         
91                     }
else{
92                         
93                         $items .=
"<tr>
94                                     <th>Trạng thái</th>
95                                     <td>
96                                         <
select onChange=\"change_stat('".$id."')\" name='status' id='".$id."' class='form-control'>
97                                             <option
value='pending_$id' >Chờ xử lý</option>
98                                             <option
value='confirmed_$id' selected>Đã hoàn thành</option>
99                                         </
select>
100                                     </td>
101                                     <th></th>
102                                 </tr>"
;
103                         
104                     }
105                     
106                     $result = $info .
"".$items;
107                     
108                      echo $result;
109                     
110                 }
111                 
112             }
113             
114         }elseif(isset($_POST[
'status'])) {
115             
116             $status = htmlentities($_POST[
'status'], ENT_QUOTES, 'UTF-8');
117             
118             
if($status != "") {
119                 
120                 $stat_arr = explode(
"_", $status);
121                 
122                 $stat_id = $stat_arr[
1];
123                 $stat_name = $stat_arr[
0];
124                 
125                 $update = $db->query(
"UPDATE basket SET status='".$stat_name."' WHERE id='".$stat_id."' LIMIT 1");
126                 
127                 
if($update) {
128                     
129                     echo
"Status updated to: $stat_name";
130                     
131                 }
132                 
133             }
134             
135         }
136         
137     }
138     
139 ?>


Gõ tìm kiếm nhanh...